#include "Entity/PhysicsProp.hpp"
#include "Common.hpp"
#include "Graphics/ISprite.hpp"
#include "Physics/IBody.hpp"
#include "Utility/EntityFactory.hpp"

#include <string>

DefineEntity< Entity::PhysicsProp > physPropDef( "ent_phys_prop" );

namespace Entity
{
	PhysicsProp::PhysicsProp( void )
		: physBody( new Physics::IBody( this ) ), 
		sprite( new Graphics::ISprite( this ) )
	{
	}

	PhysicsProp::~PhysicsProp( void )
	{
	}

	void PhysicsProp::Draw( void )
	{
		sprite->SetPosition( GetPosition() );
		sprite->SetAngle( GetAngle() );

		sprite->Draw();
	}

	Graphics::ISprite *PhysicsProp::GetSprite( void )
	{
		return sprite;
	}

	Physics::IBody *PhysicsProp::GetPhysicsBody( void )
	{
		return physBody;
	}

	float PhysicsProp::GetAngle( void ) const
	{
		return physBody->GetAngle();
	}

	void PhysicsProp::SetAngle( const float ang )
	{
		physBody->SetAngle( ang );
	}

	Math::Vectorf PhysicsProp::GetPosition( void ) const
	{
		return physBody->GetPosition();
	}

	void PhysicsProp::SetPosition( const Math::Vectorf &pos )
	{
		physBody->SetPosition( pos );
	}

	void PhysicsProp::SetSize( const Math::Vectorf &vec )
	{
		sprite->SetSize( vec );
		physBody->Initialise( Physics::PHYS_BODYTYPE_DYNAMIC, Physics::PHYS_SHAPE_BOX, vec );
		IEntity::SetSize( vec );
	}

	float PhysicsProp::GetAngularVelocity( void ) const
	{
		return physBody->GetAngularVelocity();
	}

	void PhysicsProp::SetAngularVelocity( const float vel )
	{
		physBody->SetAngularVelocity( vel );
	}

	Math::Vectorf PhysicsProp::GetLinearVelocity( void ) const
	{
		return physBody->GetLinearVelocity();
	}

	void PhysicsProp::SetLinearVelocity( const Math::Vectorf &vel )
	{
		physBody->SetLinearVelocity( vel );
	}
}